package test2;

import java.math.BigInteger;
import java.security.SecureRandom;

public class RabinKeyGenerator {
    private BigInteger p;
    private BigInteger q;
    private BigInteger n;

    public RabinKeyGenerator() {
        generateKeys();
    }

    private void generateKeys() {
        SecureRandom random = new SecureRandom();
        do {
            p = BigInteger.probablePrime(512, random);
        } while (!p.mod(BigInteger.valueOf(4)).equals(BigInteger.valueOf(3)));

        do {
            q = BigInteger.probablePrime(512, random);
        } while (!q.mod(BigInteger.valueOf(4)).equals(BigInteger.valueOf(3)));

        n = p.multiply(q);
    }

    public BigInteger getPublicKey() {
        return n;
    }

    public BigInteger[] getPrivateKey() {
        return new BigInteger[]{p, q};
    }
}
